package com.xbao.dao;

import com.xbao.model.PeriodRule;
import com.xbao.model.req.PeriodReq;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created by qingshengzheng on 18/8/27.
 */
@Mapper
public interface PeriodMapper {
    @Insert("insert into period_rule(name,starttime,endtime,day,classtime,eid,rid,subid) values(#{name},#{starttime}," +
            "#{endtime},#{day},#{classtime},#{eid},#{rid},#{subid})")
    public void addPeriod(PeriodReq periodReq);
    @Select("select * from period_rule where id=#{id}")
    public PeriodRule detailPeriod(Long id);
    @Select("select * from period_rule where  id=#{id}")
    public void deletePeriod(Long id);

    @Update("update period_rule  " +
            "<set>" +
            "<if test=\"name!=null and name !=''\">name=#{name},</if>" +
            "<if test=\"starttime!=null and starttime !=''\">&gt;= starttime=#{starttime},</if>" +
            "<if test=\"endtime!=null and endtime !=''\"> &lt;= endtime=#{endtime},</if>" +
            "<if test=\"day!=null and day !=''\">day=#{day},</if>" +
            "<if test=\"classtime!=null and classtime !=''\">classtime=#{classtime},</if>" +
            "<if test=\"eid!=null and eid !=''\">eid=#{eid},</if>" +
            "<if test=\"rid!=null and rid !=''\">rid=#{rid},</if>" +
            "<if test=\"subid!=null and subid !=''\">subid=#{subid},</if>" +
            "</set>")
    public void modifyPeriod(PeriodReq periodReq);

    @Select("select * from period_rule " +
            "<where>" +
            "<if test=\"name!=null and name !=''\">name=#{name},</if>" +
            "<if test=\"starttime!=null and starttime !=''\">starttime=#{starttime},</if>" +
            "<if test=\"endtime!=null and endtime !=''\">endtime=#{endtime},</if>" +
            "<if test=\"day!=null and day !=''\">day=#{day},</if>" +
            "<if test=\"classtime!=null and classtime !=''\">classtime=#{classtime},</if>" +
            "<if test=\"eid!=null and eid !=''\">eid=#{eid},</if>" +
            "<if test=\"rid!=null and rid !=''\">rid=#{rid},</if>" +
            "<if test=\"subid!=null and subid !=''\">subid=#{subid},</if>" +
            "<where>")
    public List<PeriodRule> queryPeriods(PeriodReq req);

}
